package com.syyo.gulimall.member.controller;

//import org.springframework.security.access.prepost.PreAuthorize;

import com.syyo.common.domain.ResultVo;
import com.syyo.common.utils.ResultUtils;
import com.syyo.gulimall.member.domain.entity.MemberReceiveAddressEntity;
import com.syyo.gulimall.member.domain.req.MemberReceiveAddressReq;
import com.syyo.gulimall.member.service.MemberReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 会员收货地址
 *
 * @author syyo
 * @email syyo@gmail.com
 * @date 2021-01-20 09:52:10
 */
@RestController
@RequestMapping("/member/memberreceiveaddress")
public class MemberReceiveAddressController {

    @Autowired
    private MemberReceiveAddressService memberReceiveAddressService;

    /**
     * 新增
     */
    @PostMapping
    // @PreAuthorize("@syyo.check('system:memberreceiveaddress:add')")
    public ResultVo add(@RequestBody MemberReceiveAddressReq req) {
        return ResultUtils.ok(memberReceiveAddressService.add(req));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    // @PreAuthorize("@syyo.check('system:memberreceiveaddress:del')")
    public ResultVo del(@PathVariable("id") Integer id) {
        return ResultUtils.ok(memberReceiveAddressService.del(id));
    }

    /**
     * 修改
     */
    @PutMapping
    // @PreAuthorize("@syyo.check('system:memberreceiveaddress:edit')")
    public ResultVo edit(@RequestBody MemberReceiveAddressReq req) {
        return ResultUtils.ok(memberReceiveAddressService.edit(req));
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Long id) {
        return ResultUtils.ok(memberReceiveAddressService.findOne(id));
    }

    /**
     * 列表
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findAll(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            MemberReceiveAddressReq req) {
        return ResultUtils.ok(memberReceiveAddressService.findAll(pageNum, pageSize, req));
    }


    /**
     * 列表
     */
    @GetMapping("/{memberId}/address")
    public List<MemberReceiveAddressEntity> listAddress(@PathVariable("memberId") Long memberId) {
        return memberReceiveAddressService.listAddress(memberId);
    }

}
